package chapter13;

public class TestGeometricObject {
  /** Main method */
  public static void main(String[] args) {
    // Declare and initialize two geometric objects
    GeometricObject geoObject1 = new Circle(5);
    GeometricObject geoObject2 = new Rectangle(5, 3);
    GeometricObject geoObject3 = new Square(10);

    System.out.println("The two objects have the same area? " +
      equalArea(geoObject1, geoObject2));
    System.out.println("The two objects have the same area? " +
            equalArea(geoObject2, geoObject3));
    System.out.println("The two objects have the same area? " +
            equalArea(geoObject1, geoObject2));

    // Display circle
    displayGeometricObject(geoObject1);
    // Display rectangle
    displayGeometricObject(geoObject2);
    displayGeometricObject(geoObject3);
    System.out.println();

    //获取三个几何图形中面积的面积最大值的对象
    System.out.println("面积最大的几何图形为:"+maxArea(geoObject1,geoObject2,geoObject3).getArea());
    //获取三个几何图形中面积的周长最大值的对象
    System.out.println("周长最大的几何图形为:"+maxArea(geoObject1,geoObject2,geoObject3).getPerimeter());

  }

  /** A method for comparing the areas of two geometric objects */
  public static boolean equalArea(GeometricObject object1,
      GeometricObject object2) {
    return object1.getArea() == object2.getArea();
  }

  /** A method for displaying a geometric object */
  public static void displayGeometricObject(GeometricObject object) {
    System.out.println();
    System.out.println("The area is " + object.getArea());
    System.out.println("The perimeter is " + object.getPerimeter());
  }

  public static GeometricObject maxArea(GeometricObject object1, GeometricObject object2, GeometricObject object3) {
    GeometricObject tmp = object1; //随意给一个默认值;

    if (object1.getArea() > object2.getArea()) {
    } else {tmp = object2;}
    if (tmp.getArea() < object3.getArea()){tmp = object3;}

    return tmp;
  }

  public static GeometricObject maxPerimeter(GeometricObject object1, GeometricObject object2, GeometricObject object3) {
    GeometricObject tmp = object1; //随意给一个默认值;

    if (object1.getPerimeter() > object2.getPerimeter()) {
    } else {tmp = object2;}
    if (tmp.getPerimeter() < object3.getPerimeter()){tmp = object3;}

    return tmp;
  }
}
